<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品分类列表')" />
</head>
<body class="gray-bg">
     <div class="container-div" style="height: 30%">
        <div class="row">
            <div class="col-sm-12 search-collapse table-bordered">
                <div>
                    <form id="formId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label style="width: 120px;">一级分类名称：</label>
                                    <input type="text" name="typeName" placeholder="请输入要查询的分类名称"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('formId','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="addFirst()"><i class="fa fa-plus"></i>&nbsp;新增一级产品分类</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
     <div class="container-div">
         <div class="row">
             <div class="col-sm-12 search-collapse table-bordered">
                 <div>
                     <form id="formId2">
                         <input type="hidden" id="parentId" name="parentId">
                         <div class="select-list">
                             <ul>
                                 <li>
                                     <label style="width: 120px;">二级分类名称：</label>
                                     <input type="text" id="typeNameSecond" name="typeNameSecond" placeholder="请输入要查询的分类名称"/>
                                 </li>
                                 <li>
                                     <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('formId2','bootstrap-table-second')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                     <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                     <a class="btn btn-warning btn-rounded btn-sm" onclick="addSecond()"><i class="fa fa-plus"></i>&nbsp;新增二级产品分类</a>
                                 </li>
                             </ul>
                         </div>
                     </form>
                 </div>
                 <table id="bootstrap-table-second"></table>
             </div>
         </div>
     </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('warehouse:partsTypeDetail:edit')}]];
        var removeFlag = [[${@permission.hasPermi('warehouse:partsTypeDetail:remove')}]];
        var prefix = ctx + "zsyh/partsTypeDetail";

        $(function() {
            queryPartsTypeFirstList();
            queryPartsTypeSecondList();
        });

        function queryPartsTypeFirstList(){
            var options = {
                id: "bootstrap-table",
                url: prefix + "/list?typeLevel=1",
                createUrl: prefix + "/add/1",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pageSize: 5,
                modalName: "产品分类",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                    {
                        field: 'id',
                        title: '分类id',
                        visible: false
                    },
                    {
                        field: 'typeImgurl',
                        align: 'center',
                        title: '分类logo',
                        formatter: function (value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                    {
                        field: 'typeName',
                        align: 'center',
                        title: '一级分类名称'
                    },
                    {
                        field: 'typeLevel',
                        align: 'center',
                        title: '分类级别'
                    },
                    {
                        field: 'typeSort',
                        align: 'center',
                        title: '排序'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editFirst(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeFirst(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }],onClickRow:function (row,$element) {
                    $("#parentId").val(row.id);
                    $("#bootstrap-table-second").bootstrapTable('refresh', {
                        query: {
                            parentId: row.id
                        }
                    });
                }
            };
            $.table.init(options);
        }

        function queryPartsTypeSecondList(){
            var options = {
                id: "bootstrap-table-second",
                url: prefix + "/listSecond",
                createUrl: prefix + "/add/2",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pageSize: 6,
                modalName: "产品分类",
                queryParams: function (params) {
                var temp ={};
                if(params){
                    if (params.pid) {
                        temp.pid = params.pid
                    }
                }
                temp.parentId = $("#parentId").val();
                temp.typeNameSecond =$("#typeNameSecond").val();
                temp.typeLevel ='2';
                temp.pageSize =6;
                temp.pageNum = params.offset / 6 + 1;
                temp.pageOffset = params.offset;
                return temp;
            },
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table-second').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table-second').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                    {
                        field: 'id',
                        title: '分类id',
                        visible: false
                    },
                    {
                        field: 'typeName',
                        align: 'center',
                        title: '一级分类名称'
                    },
                    {
                        field: 'typeNameSecond',
                        align: 'center',
                        title: '二级分类名称'
                    },
                    {
                        field: 'typeLevel',
                        align: 'center',
                        title: '分类级别'
                    },{
                        field: 'populationSalesRatio',
                        align: 'center',
                        title: '人口销售额比例'
                    },{
                        field: 'salesPaymentRatio',
                        align: 'center',
                        title: '销售额定金比例'
                    },
                    {
                        field: 'typeSort',
                        align: 'center',
                        title: '排序'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editSecond(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeSecond(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }

        function addFirst() {
            var url = prefix + '/add/1';
            $.modal.open("新增一级分类", url, '1000', '600');
        }

        function addSecond() {
            var url = prefix + '/add/2';
            $.modal.open("新增二级分类", url, '1000', '600');
        }
        
        function editFirst(id) {
            var url = prefix + "/edit/"+id;
            layer.open({
                type: 2,
                area: ['1000px','700px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "修改",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                    var $tableFlows = $('#bootstrap-table');
                    var pg = $tableFlows.bootstrapTable('getOptions').pageNumber;  //获取当前页码
                    // 跳转到对应的页面
                    $tableFlows.bootstrapTable('selectPage', parseInt(pg));
                },
                cancel: function(index) {
                    return true;
                }
            });
        }
        
        function editSecond(id) {
            var url = prefix + "/edit/"+id;
            layer.open({
                type: 2,
                area: ['1000px','500px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "修改",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                    var $tableFlows = $('#bootstrap-table-second');
                    var pg = $tableFlows.bootstrapTable('getOptions').pageNumber;  //获取当前页码
                    // 跳转到对应的页面
                    $tableFlows.bootstrapTable('selectPage', parseInt(pg));
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function removeFirst(id) {
            $.modal.confirm("确定删除该条信息吗？", function() {
                debugger;
                var url =prefix + "/remove";
                var data = { "ids": id };
                $.operate.submit(url, "post", "json", data,function () {
                    $("#bootstrap-table").bootstrapTable('refresh');
                });
            });
        }

        function removeSecond(id) {
            $.modal.confirm("确定删除该条信息吗？", function() {
                debugger;
                var url =prefix + "/remove";
                var data = { "ids": id };
                $.operate.submit(url, "post", "json", data,function () {
                    $("#bootstrap-table-second").bootstrapTable('refresh');
                });
            });
        }

    </script>
</body>
</html>